home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / list.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  3.7 KB  |  108 lines  |  [TEXT/ALFA]

  1. # Commands covered:  list
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # SCCS: @(#) list.test 1.22 97/06/23 18:19:17
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. # First, a bunch of individual tests
  18.  
  19. test list-1.1 {basic tests} {list a b c} {a b c}
  20. test list-1.2 {basic tests} {list {a b} c} {{a b} c}
  21. test list-1.3 {basic tests} {list \{a b c} {\{a b c}
  22. test list-1.4 {basic tests} "list a{}} b{} c}" "a\\{\\}\\} b{} c\\}"
  23. test list-1.5 {basic tests} {list a\[ b\] } "{a\[} b\\]"
  24. test list-1.6 {basic tests} {list c\  d\t } "{c } {d\t}"
  25. test list-1.7 {basic tests} {list e\n f\$ } "{e\n} {f\$}"
  26. test list-1.8 {basic tests} {list g\; h\\} {{g;} h\\}
  27. test list-1.9 {basic tests} "list a\\\[} b\\\]} " "a\\\[\\\} b\\\]\\\}"
  28. test list-1.10 {basic tests} "list c\\\} d\\t} " "c\\} d\\t\\}"
  29. test list-1.11 {basic tests} "list e\\n} f\\$} " "e\\n\\} f\\$\\}"
  30. test list-1.12 {basic tests} "list g\\;} h\\\\} " "g\\;\\} {h\\}}"
  31. test list-1.13 {basic tests} {list a {{}} b} {a {{}} b}
  32. test list-1.14 {basic tests} {list a b xy\\} "a b xy\\\\"
  33. test list-1.15 {basic tests} "list a b\} e\\" "a b\\} e\\\\"
  34. test list-1.16 {basic tests} "list a b\}\\\$ e\\\$\\" "a b\\}\\\$ e\\\$\\\\"
  35. test list-1.17 {basic tests} {list a\f \{\f} "{a\f} \\\{\\f"
  36. test list-1.18 {basic tests} {list a\r \{\r} "{a\r} \\\{\\r"
  37. test list-1.19 {basic tests} {list a\v \{\v} "{a\v} \\\{\\v"
  38. test list-1.20 {basic tests} {list \"\}\{} "\\\"\\}\\{"
  39. test list-1.21 {basic tests} {list a b c\\\nd} "a b c\\\\\\nd"
  40. test list-1.22 {basic tests} {list "{ab}\\"} \\{ab\\}\\\\
  41. test list-1.23 {basic tests} {list \{} "\\{"
  42. test list-1.24 {basic tests} {list} {}
  43.  
  44. # For the next round of tests create a list and then pick it apart
  45. # with "index" to make sure that we get back exactly what went in.
  46.  
  47. test list-2.1 {placeholder} {
  48. } {}
  49. set num 1
  50. proc lcheck {a b c} {
  51.     global num d
  52.     set d [list $a $b $c]
  53. ;   test list-2.$num {what goes in must come out} {lindex $d 0} $a
  54.     set num [expr $num+1]
  55. ;   test list-2.$num {what goes in must come out} {lindex $d 1} $b
  56.     set num [expr $num+1]
  57. ;   test list-2.$num {what goes in must come out} {lindex $d 2} $c
  58.     set num [expr $num+1]
  59. }
  60. lcheck a b c
  61. lcheck "a b" c\td e\nf
  62. lcheck {{a b}} {} {  }
  63. lcheck \$ \$ab ab\$
  64. lcheck \; \;ab ab\;
  65. lcheck \[ \[ab ab\[
  66. lcheck \\ \\ab ab\\
  67. lcheck {"} {"ab} {ab"}
  68. lcheck {a b} { ab} {ab }
  69. lcheck a{ a{b \{ab
  70. lcheck a} a}b }ab
  71. lcheck a\\} {a \}b} {a \{c}
  72. lcheck xyz \\ 1\\\n2
  73. lcheck "{ab}\\" "{ab}xy" abc
  74.  
  75. concat {}
  76.  
  77. # Check that tclListObj.c's SetListFromAny handles possible overlarge
  78. # string rep lengths in the source object.
  79.  
  80. proc slowsort list {
  81.     set result {}
  82.     set last [expr [llength $list] - 1]
  83.     while {$last > 0} {
  84.     set minIndex [expr [llength $list] - 1]
  85.     set min [lindex $list $last]
  86.     set i [expr $minIndex-1]
  87.     while {$i >= 0} {
  88.         if {[string compare [lindex $list $i] $min] < 0} {
  89.         set minIndex $i
  90.         set min [lindex $list $i]
  91.         }
  92.         set i [expr $i-1]
  93.     }
  94.     set result [concat $result [list $min]]
  95.     if {$minIndex == 0} {
  96.         set list [lrange $list 1 end]
  97.     } else {
  98.         set list [concat [lrange $list 0 [expr $minIndex-1]] \
  99.               [lrange $list [expr $minIndex+1] end]]
  100.     }
  101.     set last [expr $last-1]
  102.     }
  103.     return [concat $result $list]
  104. }
  105. test list-3.1 {SetListFromAny and lrange/concat results} {
  106.     slowsort {fred julie alex carol bill annie}
  107. } {alex annie bill carol fred julie}
  108.